package managesystem;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class checkUsernameServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp){
		
		String username = req.getParameter("username");
		Student s = StudentManager.readStudentByUsername(username);
		if(s==null){
			resp.setContentType("text/plain");  // Set content type of the response so that jQuery knows what it can expect.
		    resp.setCharacterEncoding("UTF-8"); // You want world domination, huh?
		    try {
		    	PrintWriter out = resp.getWriter();
		    	out.println("1");
			} catch (IOException e) {
				e.printStackTrace();
			} 
		}
		else
		{
			PrintWriter out;
			try {
				out = resp.getWriter();
				out.println("0");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	
	/*public void doPost(HttpServletRequest req, HttpServletResponse resp){
		doGet(req,resp);
	}*/
	
}